<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns:ui="http://java.sun.com/jsf/facelets"
                template="./newTemplate.xhtml"
                xmlns:p="http://primefaces.org/ui"
                xmlns:h="http://xmlns.jcp.org/jsf/html">

    <ui:define name="top"/>

    <ui:define name="left">
        <ui:include src="/inc/menu.xhtml"/>
    </ui:define>

    <ui:define name="content">
        <ui:include src="/inc/jscripts.xhtml"/>
        
        <h:form id="form">
            <p:growl id="growl" showDetail="true" life="3000" />
            <p:panel header="Задания">
                
                
                <p:menubar id="menu">
                        <p:menuitem id="Add" value="Создать" icon="ui-icon-document" 
                                         styleClass="toolbarButton" oncomplete="addSite.show()"/>
                        <p:menuitem id="Edit" value="Изменить" disabled="#{siteAction.addEdButDis}" icon="ui-icon-pencil" 
                                         styleClass="toolbarButton" onclick="editSite.show()" update=":form"/>
                        <p:menuitem id="Del" value="Удалить" disabled="true" icon="ui-icon-close" 
                                         styleClass="toolbarButton" onclick="delSite.show()" update=":form"/>
                </p:menubar>     
                <p:dataTable id="tableSites" var="site" value="#{siteAction.sites}" rowKey="#{site.id}" 
                             selection="#{siteAction.selectedSite}" selectionMode="single">
                    
                    <p:ajax event="rowSelect" listener="#{siteAction.rowSelect}" update=":form:menu"/>
                    <p:ajax event="rowUnselect"/>

                    <p:column headerText="ID">
                        <h:outputText value="#{site.id}"/>
                    </p:column>
                    <p:column headerText="Ссылка">
                        <h:outputText value="#{site.url}"/>
                    </p:column>
                    <p:column headerText="Описание">
                        <h:outputText value="#{site.caption}"/>
                    </p:column>
                </p:dataTable>
            </p:panel>
            
            <p:dialog widgetVar="addSite" header="Добавить сайт" modal="true" hideEffect="fade" showEffect="fade"
                      resizable="false" closable="false" width="30%">
              
                  <p:panelGrid columns="2" columnClasses="panelGrid">
                      <p:outputLabel value="Ссылка" style="font-weight: bold"/>    
                      <p:inputText value="#{siteAction.siteUrl}"/>

                      <p:outputLabel value="Описание" style="font-weight: bold"/>    
                      <p:inputTextarea value="#{siteAction.siteCaption}" style="width: 100%"/>

                  </p:panelGrid>
                  <p:commandButton value="OK" styleClass="dialogButtons" actionListener="#{siteAction.addSite}" 
                                   oncomplete="addSiteRequest(xhr, status, args)" update="tableSites"/>
                  <p:commandButton value="Oтмена" styleClass="dialogButtons" onclick="addSite.hide()"/>
              
            </p:dialog>
            
            <p:dialog id="editSite" widgetVar="editSite" header="Изменить сайт" modal="true" hideEffect="fade" showEffect="fade"
                      resizable="false" closable="false" width="30%">
              
                  <p:panelGrid columns="2" columnClasses="panelGrid">
                      <p:outputLabel  value="Ссылка" style="font-weight: bold"/>    
                      <p:inputText id="siteUrl" value="#{siteAction.siteUrl}"/>

                      <p:outputLabel value="Описание" style="font-weight: bold"/>    
                      <p:inputTextarea id="editSiteCaption" value="#{siteAction.siteCaption}" 
                                       style="width: 100%"/>

                  </p:panelGrid>
                  <p:commandButton value="OK" styleClass="dialogButtons" actionListener="#{siteAction.addSite}" 
                                   oncomplete="addSiteRequest(xhr, status, args)" update="tableSites"/>
                  <p:commandButton value="Oтмена" styleClass="dialogButtons" onclick="editSite.hide()"/>
              
            </p:dialog>
            
            <p:dialog widgetVar="delSite" header="Изменить сайт" modal="true" hideEffect="fade" showEffect="fade"
                    resizable="false" closable="false" width="30%">
              
                <p:outputLabel value="Вы уверены, что хотите удалить?" style="font-size: 14px; font-weight: bold; text-align: center"/>
                <p:commandButton value="OK" styleClass="dialogButtons" actionListener="#{siteAction.addSite}" 
                                   oncomplete="addSiteRequest(xhr, status, args)" update="tableSites"/>
                <p:commandButton value="Oтмена" styleClass="dialogButtons" onclick="delSite.hide()"/>
              
            </p:dialog>
            
        </h:form>
    </ui:define>

</ui:composition>
